<?php
$judul = '';
$link = '';
$jenis = array('1' => 'rumah', '2' => 'apartemen', '3' => 'tanah', '4' => 'ruko dan kios',
    '5' => 'ruang kantor', '6' => 'indekost', '7' => 'hotel dan villa', '8' => 'gudang', '9' => 'lainnya');
$beli = array('1' => 'dijual', '2' => 'disewa', '3' => 'dicari');

$sertifikasi = array('1' => 'SHM-Sertifikat', '2' => 'Hak Milik', '3' => 'HGB', '4' => 'lainnya(PPJB,adat,dll)');
$furnitur = array('1' => 'Fully furnished', '2' => 'Semi furnished', '3' => 'Unfurnished');
$pilihan = array('1' => 'semua', '2' => 'villa', '3' => 'rumah', '4' => 'condotel',
    '5' => 'apartemen', '6' => 'komersial (ruko, toko, office)');

//$provinsi = array('jakarta' => 'DKI Jakarta', 'jateng' => 'Jawa Tengah', 'jabar' => 'Jawa Barat');

function generate_option($array = array(), $sel = '') {
    $x = '';
    foreach ($array as $key => $val) {
        if ($key == $sel) {
            $selected = set_select('option', $sel, TRUE);
        } else {
            $selected = set_select('option', $sel);
        }
        echo '<option value="' . $key . '" ' . $selected . '>' . $val . '</option>';
    }
    return $array[$x];
}

function generate_input($type = '', $array = array(), $name = '', $sel = '') {
    if ($type == 'radio') {
        foreach ($array as $key => $val) {
            echo '<input type="' . $type . '" name="' . $name . '" value="' . $key . '"/>' . $val . '&nbsp;';
        }
    } else {
        foreach ($array as $key => $val) {
            echo '<label class="checkbox" for="' . $key . '">
            <input class="span1" type="' . $type . '" name="' . $key . '" value="' . $key . '" id="' . $key . '" data-toggle="checkbox"/>' . $val . '&nbsp;
            </label>';
        }
    }
}
?>
<div class="page properti_baru">
    <div class="container">
        <div class="form_caripropertibaru">
            <form method="get" action="<?php echo site_url('properti_baru/cari') ?>">
                <fieldset>
                    <legend>Cari Properti Baru</legend>
                    <div class="row">
                        <div class="span3">
                            <select name="provinsi" class="select-block span3" onChange="handleOnChange(this);">
                                <option value="0" selected>
                                    -- Pilih provinsi --
                                </option>
                                <?php
                                $i = 1;
                                foreach ($provinsi as $value) {
                                    echo "<option value='" . $i . "'";
                                    if ($this->input->get('provinsi', TRUE) == $i) {
                                        echo "selected";
                                    }
                                    $i++;
                                    echo ">";
                                    echo $value->prov_nama;
                                    echo "</option>";
                                }
                                ?>
                            </select>
                            <select name="kota" id="dom_kota" class="select-block span3">
                                <option value="0">-- Pilih kota --</option>
                                <?php
                                $i = 1;
                                foreach ($kota as $value) {
                                    echo "<option value='" . $i . "'";
                                    if ($this->input->get('kota', TRUE) == $i) {
                                        echo "selected";
                                    }
                                    $i++;
                                    echo ">";
                                    echo $value->kota_nama;
                                    echo "</option>";
                                }
                                ?>
                            </select>
                        </div>
                        <div class="span2">
                            <!--<label class="checkbox span1" for="semua">
                                <input type="checkbox" name="semua" value="1" id="semua" data-toggle="checkbox"
                            <?php
                            if ($this->input->get('semua', TRUE) == '1') {
                                echo "checked";
                            }
                            ?>
                                       >
                                Semua
                            </label>-->
                            <label class="checkbox span1" for="rumah">
                                <input type="checkbox" name="rumah" value="1" id="rumah" data-toggle="checkbox"
                                <?php
                                if ($this->input->get('rumah', TRUE) == '1') {
                                    echo "checked";
                                }
                                ?>
                                       >
                                Rumah
                            </label>
                            <label class="checkbox span1" for="villa">
                                <input type="checkbox" name="villa" value="1" id="villa" data-toggle="checkbox"
                                <?php
                                if ($this->input->get('villa', TRUE) == '1') {
                                    echo "checked";
                                }
                                ?>
                                       >
                                Villa
                            </label>

                        </div>
                        <div class="span2">
                            <label class="checkbox span1" for="apartemen">
                                <input type="checkbox" name="apartemen" value="1" id="apartemen" data-toggle="checkbox"
                                <?php
                                if ($this->input->get('apartemen', TRUE) == '1') {
                                    echo "checked";
                                }
                                ?>
                                       >
                                Apartemen
                            </label>
                            <label class="checkbox span1" for="condotel">
                                <input type="checkbox" name="condotel" value="1" id="condotel" data-toggle="checkbox"
                                <?php
                                if ($this->input->get('condotel', TRUE) == '1') {
                                    echo "checked";
                                }
                                ?>
                                       >
                                Condotel
                            </label>

                        </div>
                        <div class="span3">

                            <label class="checkbox span3" for="komersial">
                                <input type="checkbox" name="komersial" value="1" id="komersial" data-toggle="checkbox"
                                <?php
                                if ($this->input->get('komersial', TRUE) == '1') {
                                    echo "checked";
                                }
                                ?>
                                       >
                                Komersial (Toko, Ruko, Office)
                            </label>
                        </div>
                    </div>
                    <div class="row">
                        <input type="text"
                               value="<?php if ($this->input->get('keyword', TRUE)) echo $this->input->get('keyword', TRUE); ?>"
                               placeholder="Masukkan kata kunci : area, nama real estate" name="keyword" class="span7 katakunci" />
                        <input type="submit" class="btn btn-primary btn-small span2 submitcaripropertibaru" value="Cari" />
                    </div>
                    <div class="fieldcek">
                        <?php
                        echo validation_errors();
                        ?>
                    </div>
                </fieldset>     
            </form>
            <div class="row-fluid propertipremium">
                <legend>Properti Premium</legend>
                <ul class="thumbnails">
                    <?php
                    // foreach ($prop_baru as $value) {                        
                    //     if($value->isPremium){
                    //         echo '<li class="span3">';
                    //         echo '<a href="'.site_url('properti_baru/detail/'.$value->id_properti_baru).'" class="thumbnail">';
                    //         echo '<img data-src="holder.js/300x200" alt="" src="'.$value->url.'">';
                    //         echo '<div class="caption">';
                    //         echo '<strong>'.$value->judul.'</strong>';
                    //         echo '<p>'.$value->nama.'</p>';
                    //         echo '</div></a></li>';
                    //     }
                    // }

                    ?>
                    <?php for ($count = 0; $count < sizeof($output['prop_baru']); $count++) { 
                        if($output['prop_baru'][$count]['is_premium']==1){
                            
                        ?>

                        <li class="span3">
                            <a href="<?php echo site_url('properti_baru/detail/' . $output['prop_baru'][$count]['id']); ?>" class="thumbnail">
                                <?php
                                $url = "";
                                if ($output['prop_baru'][$count]['picture'] != "") {
                                    $url = base_url() . 'pictures/properti_baru/' . $output['prop_baru'][$count]['picture'];
                                } else {
                                    $url = base_url() . 'assets/img/rumah_default3.png';
                                }
                                ?>
                                <img data-src="" alt="" height="200px" width="200px" src="<?php echo $url; ?>"> 
                                <div class="caption">
                                    <strong><?php 
                                        $judul = $output['prop_baru'][$count]['judul'];
                                        if(strlen($judul)>20){
                                            echo substr($judul, 0, 23)."...";
                                        } else{
                                            echo $judul;
                                        }
                                    ?>
                                    </strong>
                                    <p><?php echo $output['prop_baru'][$count]['nama_developer']; ?></p>
                                </div>
                            </a>
                        </li>
                        <?php
                        $count++;
                    }
                    if($count==4){
                        break; //just show four premium properties
                    }
                }
                    ?>
                </ul>
                <div class="span3 pull-right"><?php echo anchor(site_url('properti_baru/properti_premium'), 'Properti Premium Lainnya'); ?></div>

            </div>
            <div class"row-fluid propertipremium">
                 <legend>Properti Baru Bulan Ini</legend>
                <ul class="thumbnails" width="200" height="200">
                    <?php for ($count = 0; $count < sizeof($output['prop_baru']); $count++) { 
                        $tgl_upload = explode("-", $output['prop_baru'][$count]['tgl_upload']);
                        
                        if($output['prop_baru'][$count]['is_premium']==0 && $tgl_upload[1]==date("m")){
                            for ($i=0; $i < 10; $i++) { 
                                # code...
                            
                    ?>
                        <li class="span3">
                            <a href="<?php echo site_url('properti_baru/detail/' . $output['prop_baru'][$count]['id']); ?>" class="thumbnail">
                                <?php
                                $url = "";
                                if ($output['prop_baru'][$count]['picture'] != "") {
                                    $url = base_url() . 'pictures/properti_baru/' . $output['prop_baru'][$count]['picture'];
                                } else {
                                    $url = base_url() . 'assets/img/rumah_default3.png';
                                }
                                ?>
                                <img data-src="" alt="" height="200px" width="200px" src="<?php echo $url; ?>"> 
                                <div class="caption">
                                    <strong><?php 
                                        $judul = $output['prop_baru'][$count]['judul'];
                                        if(strlen($judul)>20){
                                            echo substr($judul, 0, 23)."...";
                                        } else{
                                            echo $judul;
                                        }
                                    ?>
                                    </strong>
                                    <p><?php echo $output['prop_baru'][$count]['nama_developer']; ?></p>
                                </div>
                            </a>
                        </li>
                        <?php
                    }
                        //$count++;
                    }
                }
                    ?>
                </ul>
            </div>
        </div>
    </div>
</div>
<!--
<h3>Properti Baru Bulan Ini</h3>
<?php
foreach ($prop_baru as $value) {
    if (!$value->isPremium) {
        echo '<strong>' . anchor(site_url('properti_baru/detail/' . $value->id_properti_baru), $value->judul) . '</strong><br/>';
        echo $value->nama . '<br/>';
        echo '<img src="' . $value->url . '" height="200" width="300">';
    }
}
?>
<hr/>
<h3>Listing Properti Baru</h3>
<?php echo anchor(site_url('listing/baru_lainnya'), 'Properti Baru Lainnya'); ?>-->